package agency.web.app.domain;


import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name = "tour")
public abstract class AbstractTour  implements Tour{

	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "TOUR_ID")
	private int tourId;
	
	@Column(name = "TYPE")
	private String type;

	@ManyToMany(targetEntity = Country.class, fetch = FetchType.EAGER)
	@JoinTable(name = "tour_has_country", joinColumns = { @JoinColumn(name = "TOUR_ID") }, inverseJoinColumns = { @JoinColumn(name = "COUNTRY_ID") })
	private List<Country> countries;
	
	@Column(name = "REGION")
	private String region;
	
	@Column(name = "PRICE_1")
	private int pricePerPerson;
	
	@Column(name = "HOTEL")
	private String hotelName;
	
	@Column(name = "TRANSPORT")
	private String transport;
	
	@Column(name = "HOT_TOUR")
	private boolean isHotTour;
	
	@OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "TRIP_ID")
	private List<Trip> trips;
	
	public AbstractTour(List<Country> country, String region, int pricePerPerson, String hotel, String transport, boolean hot, List<Trip> trips){
		
		this.countries = country;
		this.region = region;
		this.pricePerPerson = pricePerPerson;
		hotelName = hotel;
		this.transport = transport;
		isHotTour = hot;
		this.trips = trips;
		
	}
	
	public int getTourId() {
		return tourId;
	}

    public void setTourId(int tourId) {
		this.tourId = tourId;
	}

    public String getType() {
    	if ( this instanceof ExcursionTour)
			return "ExcursionTour";
		if ( this instanceof ShoppingTour)
			return "ShoppingTour";
		if ( this instanceof ReposeTour)
			return "ReposeTour";
		return "UnknownType";
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	
	public int getPricePerPerson() {
		return pricePerPerson;
	}

	public void setPricePerPerson(int pricePerPerson) {
		this.pricePerPerson = pricePerPerson;
	}

	public String getHotelName() {
		return hotelName;
	}

	public void setHotelName(String hotelName) {
		this.hotelName = hotelName;
	}

	public String getTransport() {
		return transport;
	}

	public void setTransport(String transport) {
		this.transport = transport;
	}

	public boolean isHotTour() {
		return isHotTour;
	}

	public void setHotTour(boolean isHotTour) {
		this.isHotTour = isHotTour;
	}

	public List<Country> getCountries() {
		return countries;
	}

	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}

	public List<Trip> getTrips() {
		return trips;
	}

	public void setTrips(List<Trip> trips) {
		this.trips = trips;
	}

	

}
